//
//  DeleteBottomView.m
//  JiaoX
//
//  Created by yinqy on 15/3/19.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "DeleteBottomView.h"

@interface DeleteBottomView()
{
    UIButton *_selectAllBtn;
    UIButton *_deleteBtn;
}

@end
@implementation DeleteBottomView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setSize:CGSizeMake(JXScreenW, 49)];
        
        UIView *splite = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 1)];
        [splite setBackgroundColor:JXColor(204, 204, 204)];
        [self addSubview:splite];
        
        _selectAllBtn = [[UIButton alloc]init];
        [_selectAllBtn setImage:[UIImage imageNamed:@"Unselected"] forState:UIControlStateNormal];
        [_selectAllBtn setImage:[UIImage imageNamed:@"Selected"] forState:UIControlStateSelected];
        [_selectAllBtn setTitle:@"全选" forState:UIControlStateNormal];
        [_selectAllBtn setTitleColor:JXThemeColor forState:UIControlStateNormal];
        [_selectAllBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [_selectAllBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
        CGFloat selectBtnW = [_selectAllBtn.titleLabel.text sizeWithFont:_selectAllBtn.titleLabel.font].width+5+_selectAllBtn.imageView.image.size.width;
        [_selectAllBtn setFrame:CGRectMake(7, 0, selectBtnW, 49)];
        [_selectAllBtn addTarget:self action:@selector(selectBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_selectAllBtn];
        
        UIButton *deleteBtn = [[UIButton alloc]init];
        [deleteBtn setSize:CGSizeMake(66, 26)];
        [deleteBtn setX:self.width-deleteBtn.width-10];
        [deleteBtn setCenterY:self.centerY];
        [deleteBtn.layer setBorderWidth:0.5];
        [deleteBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
        [deleteBtn.layer setBorderColor:JXThemeColor.CGColor];
        [deleteBtn.layer setMasksToBounds:YES];
        [deleteBtn setAdjustsImageWhenHighlighted:NO];
        [deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [deleteBtn setTitleColor:JXThemeColor forState:UIControlStateNormal];
        [deleteBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
        [deleteBtn.titleLabel setTextColor:JXThemeColor];
        [deleteBtn setImage:[UIImage imageNamed:@"ic_delete_theme"] forState:UIControlStateNormal];
        [self addSubview:deleteBtn];
        _deleteBtn = deleteBtn;
        [_deleteBtn addTarget:self action:@selector(deleteBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

-(void)selectBtnClick{
    [_selectAllBtn setSelected:!_selectAllBtn.selected];
    if ([_delegate respondsToSelector:@selector(selectAllBtnClick:)]) {
        [_delegate selectAllBtnClick:_selectAllBtn];
    }
}

-(void)deleteBtnClick{
    if ([_delegate respondsToSelector:@selector(deleteBtnClick)]) {
        [_delegate deleteBtnClick];
    }
}

-(void)setSelect:(BOOL)select{
    _selectAllBtn.selected = select;
}
@end
